package com.jiyi.activity.iot;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jiyi.bean.iot.FireAlarmBean;
import com.jiyi.exception.SampleProgressObserver;
import com.jiyi.retrofit.IotHttpMethods;
import com.swift.base.ActivityBase;
import com.swift.maintenance.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/4/26.
 */

public class FireAlarmDetailActivity extends ActivityBase {
    @BindView(R.id.tvBack)
    TextView tvBack;
    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.tvSearch)
    TextView tvSearch;
    @BindView(R.id.ivHint)
    ImageView ivHint;
    @BindView(R.id.top_layout)
    RelativeLayout topLayout;

    String sn,typeName;
    int type;
    @BindView(R.id.tvUnitName)
    TextView tvUnitName;
    @BindView(R.id.tvAddress)
    TextView tvAddress;
    @BindView(R.id.tvSummary)
    TextView tvSummary;
    @BindView(R.id.tvHappenTime)
    TextView tvHappenTime;
    @BindView(R.id.tvReceiveTime)
    TextView tvReceiveTime;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fire_alarm_detail);
        ButterKnife.bind(this);
        init();
    }

    void init() {
        getIntentData();
        setTop();
        if (!TextUtils.isEmpty(sn)) {
            getData();
        }
    }

    private void getIntentData() {
        sn = getIntent().getStringExtra("sn");
        type = getIntent().getIntExtra("type", 1);
        typeName = getIntent().getStringExtra("typeName");
    }

    private void setTop() {
        tvBack.setText("");
        tvTitle.setText(typeName+"监测详情");
        tvSearch.setVisibility(View.INVISIBLE);
    }

    void getData() {
        IotHttpMethods.getInstance().getFireAlarm(type, sn)
                .subscribe(new SampleProgressObserver<FireAlarmBean>(this) {
                    @Override
                    public void onNext(FireAlarmBean fireAlarmBean) {
                        fillData(fireAlarmBean);
                    }
                });
    }

    void fillData(FireAlarmBean fireAlarmBean) {
        tvUnitName.setText(fireAlarmBean.getMonitorname());
        tvAddress.setText(fireAlarmBean.getUser_add());
        tvSummary.setText(fireAlarmBean.getAlarm_summary());
        tvHappenTime.setText(fireAlarmBean.getHappen_time());
        tvReceiveTime.setText(fireAlarmBean.getReceive_time());
    }

    @OnClick({R.id.tvBack})
    public void onClick(View view) {
        Intent intent;
        switch (view.getId()) {
            case R.id.tvBack:
                finish();
                break;

        }
    }
}
